package com.yanjiang;

import com.mysql.jdbc.Connection;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class News {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            String url = "jdbc:mysql://127.0.0.1:3306/kgcnews";
            String user = "root";
            String pass = "123456";
            Connection connection  = (Connection) DriverManager.getConnection(url,user,pass);
            Statement statement= connection.createStatement();
            String sql="SELECT * FROM  news_detail";
            ResultSet resultSet=statement.executeQuery(sql);
            while (resultSet.next()){
                int id=resultSet.getInt("id");
                String name = resultSet.getString("title");
                System.out.println(id + name);
            }
            resultSet.close();
            statement.close();
            connection.close();
        }catch (SQLException | ClassNotFoundException e){
            e.printStackTrace();
        }

    }
}
